package com.example.backend.service.impl;

import com.example.backend.entity.PeiSong;
import com.example.backend.entity.PeiSongStatusEnum;
import com.example.backend.entity.vo.ShowQs;
import com.example.backend.mapper.PeiSongMapper;
import com.example.backend.service.IPeiSongService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service    // 将当前类注册为服务类
public class PeiSongService implements IPeiSongService {
    @Resource
    private PeiSongMapper peiSongMapper;

    // 增加配送信息
    public boolean addPsks(PeiSong peiSong){
        // 若前端未传状态，强制设置为默认值（增强健壮性）
        if (peiSong.getPszt() == null) {
            peiSong.setPszt(PeiSongStatusEnum.UNDELIVERED.getCode());
        }
        return peiSongMapper.insert(peiSong) > 0;
    }

    // 送达后，删除配送订单信息
    public boolean deletePsdd(PeiSong peiSong){
        if(peiSong.getPszt() == 2){
            return peiSongMapper.deleteById(peiSong) > 0;
        }
        return false;
    }

    // 更新配送信息
    public boolean updatePsdd(PeiSong peiSong) {
        return peiSongMapper.updateById(peiSong) > 0;
    }


    // 根据配送id查询配送信息
    public PeiSong queryPsddBypsid(Integer psid) {
        return peiSongMapper.selectById(psid);
    }

    // 查询所有配送信息
    public List<PeiSong> queryPsdd() {
        return peiSongMapper.selectList(null);
    }

    @Override
    public PeiSong queryPsddByddid(Integer ddid) {
        return peiSongMapper.selectById(ddid);
    }

    public boolean updatePszt(PeiSong peiSong) {
        return peiSongMapper.updateByDdId(peiSong) > 0;
    }

    @Override
    public List<ShowQs> queryPsWithPszt() {
        return peiSongMapper.queryPsWithPszt();
    }

    @Override
    public List<ShowQs> queryPsing(Integer qsid) {
        return peiSongMapper.queryPsing(qsid);
    }

    @Override
    public List<ShowQs> querySuccess(Integer qsid) {
        return peiSongMapper.querySuccess(qsid);
    }
}
